
/**
* @module sessionIdProcessor
* @author: Hjava
* @description:
* @since: 2019-04-20 11:43:08
*/
Object.defineProperty(exports, "__esModule", { value: true });
var SessionIdProcessor = /** @class */ (function () {
    function SessionIdProcessor() {
        this._separtor = '-';
        this._sessionIdReg = new RegExp("\\d" + this._separtor + "\\d");
    }
    SessionIdProcessor.prototype.isSessionId = function (sessionId) {
        return this._sessionIdReg.test(sessionId);
    };
    SessionIdProcessor.prototype.create = function (_a) {
        var uid = _a.uid, channelId = _a.channelId, sid = _a.sid;
        /*
        uid：
        1.单聊为:对方大象uid
        2.群聊为:群id
        3.公众号用户侧为:公众号id
        4.公众号客服侧为:公众号id_peeruid
        只有公众号客服侧peeruid才有值，表示聊天的对方的大象uid
        */
        if (sid) {
            return "" + channelId + this._separtor + uid + this._separtor + sid;
        }
        else {
            return "" + channelId + this._separtor + uid;
        }
    };
    SessionIdProcessor.prototype.parseSessionId = function (sessionId) {
        var ids = sessionId.split(this._separtor);
        var sid = '';
        if (ids[2]) {
            for (var i = 2; i < ids.length; i++) {
                if (i === (ids.length - 1)) {
                    sid += ids[i];
                }
                else {
                    sid += ids[i] + this._separtor;
                }
            }
        }
        return {
            channelId: this._getInt(ids[0], 0),
            uid: ids[1],
            sid: sid || ''
        };
    };
    SessionIdProcessor.prototype._getInt = function (value, defaultValue) {
        var number = parseInt(value);
        if (isNaN(number)) {
            return defaultValue;
        }
        return number;
    };
    return SessionIdProcessor;
}());
exports.default = new SessionIdProcessor();


//# sourceURL=webpack://MTDX/./src/extra/utils/sessionIdProcessor.ts?